﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability_Management.Domain;
using Traceability_Management.ErrorCode;
using Traceability_Management.Infrastructure.Interfaces;
using Traceability_Management.Read.Api.Application.Command.Processiings_CompanyWay;
using Traceability_Management.Read.Api.Application.Command.Processiings_FourWay;

namespace Traceability_Management.Read.Api.Application.CommandHandler.Processiings_CompanyWay
{
    public class FirstProcessiings_CompanyCompanyWayCommandHandler : IRequestHandler<FirstProcessiings_CompanyCompanyWayCommand, ApiResult<Processiings_Company>>
    {
        IBaseReponsitory<Processiings_Company> Processiings_Company;

        public FirstProcessiings_CompanyCompanyWayCommandHandler(IBaseReponsitory<Processiings_Company> Processiings_Company)
        {
            this.Processiings_Company = Processiings_Company;
        }

        public async Task<ApiResult<Processiings_Company>> Handle(FirstProcessiings_CompanyCompanyWayCommand request, CancellationToken cancellationToken)
        {
            var Bachlist = await Processiings_Company.GetQuery().FirstOrDefaultAsync(c => c.Rabit_Batch == request.Batch);
            if (Bachlist != null)
            {
                return new ApiResult<Processiings_Company>
                {
                    Code = ApiEnum.Success,
                    Message = "加载成功了",
                    Data = Bachlist
                };
            }
            else
            {
                return new ApiResult<Processiings_Company>
                {
                    Code = ApiEnum.Success,
                    Message = "请设置信息",
                };
            }
        }
    }
}
